<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <meta charset="utf-8"/>
    <title>Swoole-API-文档</title>
    <meta name="author" content=""/>
    <meta name="description" content=""/>

    <link href="../css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/prism.css" rel="stylesheet" media="all"/>
    <link href="../css/template.css" rel="stylesheet" media="all"/>
    
    <!--[if lt IE 9]>
    <script src="../js/html5.js"></script>
    <![endif]-->
    <script src="../js/jquery-1.11.0.min.js"></script>
    <script src="../js/ui/1.10.4/jquery-ui.min.js"></script>
    <script src="../js/bootstrap.min.js"></script>
    <script src="../js/jquery.smooth-scroll.js"></script>
    <script src="../js/prism.min.js"></script>
    <!-- TODO: Add http://jscrollpane.kelvinluck.com/ to style the scrollbars for browsers not using webkit-->
    <script type="text/javascript">
    function loadExternalCodeSnippets() {
        Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
            var src = pre.getAttribute('data-src');
            var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
            var language = 'php';

            var code = document.createElement('code');
            code.className = 'language-' + language;

            pre.textContent = '';

            code.textContent = 'Loading…';

            pre.appendChild(code);

            var xhr = new XMLHttpRequest();

            xhr.open('GET', src, true);

            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4) {

                    if (xhr.status < 400 && xhr.responseText) {
                        code.textContent = xhr.responseText;

                        Prism.highlightElement(code);
                    }
                    else if (xhr.status >= 400) {
                        code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
                    }
                    else {
                        code.textContent = '✖ Error: File does not exist or is empty';
                    }
                }
            };

            xhr.send(null);
        });
    }

    $(document).ready(function(){
        loadExternalCodeSnippets();
    });
    $('#source-view').on('shown', function () {
        loadExternalCodeSnippets();
    })
</script>

    <link rel="shortcut icon" href="../images/favicon.ico"/>
    <link rel="apple-touch-icon" href="../images/apple-touch-icon.png"/>
    <link rel="apple-touch-icon" sizes="72x72" href="../images/apple-touch-icon-72x72.png"/>
    <link rel="apple-touch-icon" sizes="114x114" href="../images/apple-touch-icon-114x114.png"/>
</head>
<body>

<div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                <i class="icon-ellipsis-vertical"></i>
            </a>
            <a class="brand" href="../index.html">Swoole-API-文档</a>

            <div class="nav-collapse">
                <ul class="nav pull-right">
                                        <li class="dropdown">
                        <a href="../index.html" class="dropdown-toggle" data-toggle="dropdown">
                            API Documentation <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                                                        <li><a href="../namespaces/Swoole.html">\Swoole</a></li>
                                                    </ul>
                    </li>
                                        <li class="dropdown" id="charts-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            Charts <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="../graphs/class.html">
                                    <i class="icon-list-alt"></i>&#160;Class hierarchy diagram
                                </a>
                            </li>
                        </ul>
                    </li>
                    <li class="dropdown" id="reports-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            Reports <b class="caret"></b>
                        </a>
                        <ul class="dropdown-menu">
                            <li>
                                <a href="../reports/errors.html">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <i class="icon-list-alt"></i>&#160;Errors <span class="label label-info pull-right">71</span>
                                </a>
                            </li>
                            <li>
                                <a href="../reports/markers.html">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <i class="icon-list-alt"></i>&#160;Markers <span class="label label-info pull-right">0</span>
                                </a>
                            </li>
                            <li>
                                <a href="../reports/deprecated.html">
                                                                                                            <i class="icon-list-alt"></i>&#160;Deprecated <span class="label label-info pull-right">0</span>
                                </a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--<div class="go_to_top">-->
    <!--<a href="#___" style="color: inherit">Back to top&#160;&#160;<i class="icon-upload icon-white"></i></a>-->
    <!--</div>-->
</div>

<div id="___" class="container-fluid">
        <section class="row-fluid">
        <div class="span2 sidebar">
                                <div class="accordion" style="margin-bottom: 0">
        <div class="accordion-group">
            <div class="accordion-heading">
                                    <a class="accordion-toggle " data-toggle="collapse" data-target="#namespace-173800253"></a>
                                <a href="../namespaces/default.html" style="margin-left: 30px; padding-left: 0">\</a>
            </div>
            <div id="namespace-173800253" class="accordion-body collapse in">
                <div class="accordion-inner">

                                                    <div class="accordion" style="margin-bottom: 0">
        <div class="accordion-group">
            <div class="accordion-heading">
                                    <a class="accordion-toggle collapsed" data-toggle="collapse" data-target="#namespace-1477779829"></a>
                                <a href="../namespaces/Swoole.html" style="margin-left: 30px; padding-left: 0">Swoole</a>
            </div>
            <div id="namespace-1477779829" class="accordion-body collapse ">
                <div class="accordion-inner">

                                                    <div class="accordion" style="margin-bottom: 0">
        <div class="accordion-group">
            <div class="accordion-heading">
                                    <a class="accordion-toggle collapsed" data-toggle="collapse" data-target="#namespace-812215378"></a>
                                <a href="../namespaces/Swoole.Http.html" style="margin-left: 30px; padding-left: 0">Http</a>
            </div>
            <div id="namespace-812215378" class="accordion-body collapse ">
                <div class="accordion-inner">

                    
                    <ul>
                                                                                                    <li class="class"><a href="../classes/Swoole.Http.Client.html">Client</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Http.Request.html">Request</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Http.Response.html">Response</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Http.Server.html">Server</a></li>
                                            </ul>
                </div>
            </div>
        </div>
    </div>

                                                    <div class="accordion" style="margin-bottom: 0">
        <div class="accordion-group">
            <div class="accordion-heading">
                                    <a class="accordion-toggle collapsed" data-toggle="collapse" data-target="#namespace-1765007207"></a>
                                <a href="../namespaces/Swoole.WebSocket.html" style="margin-left: 30px; padding-left: 0">WebSocket</a>
            </div>
            <div id="namespace-1765007207" class="accordion-body collapse ">
                <div class="accordion-inner">

                    
                    <ul>
                                                                                                    <li class="class"><a href="../classes/Swoole.WebSocket.Frame.html">Frame</a></li>
                                                    <li class="class"><a href="../classes/Swoole.WebSocket.Server.html">Server</a></li>
                                            </ul>
                </div>
            </div>
        </div>
    </div>

                    
                    <ul>
                                                                                                    <li class="class"><a href="../classes/Swoole.Atomic.html">Atomic</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Buffer.html">Buffer</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Client.html">Client</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Lock.html">Lock</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Process.html">Process</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Redis.html">Redis</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Server.html">Server</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Table.html">Table</a></li>
                                                    <li class="class"><a href="../classes/Swoole.Timer.html">Timer</a></li>
                                            </ul>
                </div>
            </div>
        </div>
    </div>

                    
                    <ul>
                                                                                                    <li class="class"><a href="../classes/swoole_atomic.html">swoole_atomic</a></li>
                                                    <li class="class"><a href="../classes/swoole_buffer.html">swoole_buffer</a></li>
                                                    <li class="class"><a href="../classes/swoole_client.html">swoole_client</a></li>
                                                    <li class="class"><a href="../classes/swoole_http_client.html">swoole_http_client</a></li>
                                                    <li class="class"><a href="../classes/swoole_http_request.html">swoole_http_request</a></li>
                                                    <li class="class"><a href="../classes/swoole_http_response.html">swoole_http_response</a></li>
                                                    <li class="class"><a href="../classes/swoole_http_server.html">swoole_http_server</a></li>
                                                    <li class="class"><a href="../classes/swoole_lock.html">swoole_lock</a></li>
                                                    <li class="class"><a href="../classes/swoole_process.html">swoole_process</a></li>
                                                    <li class="class"><a href="../classes/swoole_redis.html">swoole_redis</a></li>
                                                    <li class="class"><a href="../classes/swoole_server.html">swoole_server</a></li>
                                                    <li class="class"><a href="../classes/swoole_server_port.html">swoole_server_port</a></li>
                                                    <li class="class"><a href="../classes/swoole_table.html">swoole_table</a></li>
                                                    <li class="class"><a href="../classes/swoole_websocket_server.html">swoole_websocket_server</a></li>
                                            </ul>
                </div>
            </div>
        </div>
    </div>

        </div>
    </section>
    <section class="row-fluid">
        <div class="span10 offset2">
            <div class="row-fluid">
                <div class="span8 content class">
                    <nav>
                                                <a href="../namespaces/Swoole.WebSocket.html">\Swoole\WebSocket</a> <i class="icon-level-up"></i>
                                            </nav>
                    <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal"><i class="icon-code"></i></a>

                    <h1><small>\Swoole\WebSocket</small>Server</h1>
                    <p><em>Class swoole_http_server</em></p>
                    <p>内置 Websocket 服务器</p>
                    
                                        
                    <section id="summary">
                        <h2>Summary</h2>
                        <section class="row-fluid heading">
                            <section class="span4">
                                <a href="#methods">Methods</a>
                            </section>
                            <section class="span4">
                                <a href="#properties">Properties</a>
                            </section>
                            <section class="span4">
                                <a href="#constants">Constants</a>
                            </section>
                        </section>
                        <section class="row-fluid public">
                            <section class="span4">
                                                                    <a href="../classes/Swoole.Http.Server.html#method_setGlobal" class="">setGlobal()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method___construct" class="">__construct()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_on" class="">on()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_set" class="">set()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_start" class="">start()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_send" class="">send()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_sendto" class="">sendto()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_close" class="">close()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_taskwait" class="">taskwait()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_task" class="">task()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_sendMessage" class="">sendMessage()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_finish" class="">finish()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_heartbeat" class="">heartbeat()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_connection_info" class="">connection_info()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_connection_list" class="">connection_list()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_reload" class="">reload()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_shutdown" class="">shutdown()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_addlistener" class="">addlistener()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_stats" class="">stats()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_after" class="">after()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_listen" class="">listen()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_addProcess" class="">addProcess()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_addtimer" class="">addtimer()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_deltimer" class="">deltimer()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_tick" class="">tick()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_clearAfter" class="">clearAfter()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_handler" class="">handler()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_sendfile" class="">sendfile()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_bind" class="">bind()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_getSocket" class="">getSocket()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_exist" class="">exist()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_defer" class="">defer()</a><br />
                                                                    <a href="../classes/Swoole.Server.html#method_getClientInfo" class="">getClientInfo()</a><br />
                                                                    <a href="../classes/Swoole.WebSocket.Server.html#method_push" class="">push()</a><br />
                                                                    <a href="../classes/Swoole.WebSocket.Server.html#method_pack" class="">pack()</a><br />
                                                            </section>
                            <section class="span4">
                                                                    <a href="../classes/Swoole.Server.html#property_master_pid" class="">$master_pid</a><br />
                                                                    <a href="../classes/Swoole.Server.html#property_manager_pid" class="">$manager_pid</a><br />
                                                                    <a href="../classes/Swoole.Server.html#property_worker_id" class="">$worker_id</a><br />
                                                                    <a href="../classes/Swoole.Server.html#property_worker_pid" class="">$worker_pid</a><br />
                                                                    <a href="../classes/Swoole.Server.html#property_taskworker" class="">$taskworker</a><br />
                                                                    <a href="../classes/Swoole.Server.html#property_connections" class="">$connections</a><br />
                                                            </section>
                            <section class="span4">
                                                                    <em>No constants found</em>
                                                            </section>
                        </section>
                        <section class="row-fluid protected">
                            <section class="span4">
                                                                    <em>No protected methods found</em>
                                                            </section>
                            <section class="span4">
                                                                    <em>No protected properties found</em>
                                                            </section>
                            <section class="span4">
                                <em>N/A</em>
                            </section>
                        </section>
                        <section class="row-fluid private">
                            <section class="span4">
                                                                    <em>No private methods found</em>
                                                            </section>
                            <section class="span4">
                                                                    <em>No private properties found</em>
                                                            </section>
                            <section class="span4">
                                <em>N/A</em>
                            </section>
                        </section>
                    </section>
                </div>
                <aside class="span4 detailsbar">
                                        
                    
                    <dl>
                        <dt>File</dt>
                            <dd><a href="../files/Websocket.Server.html"><div class="path-wrapper">Websocket/Server.php</div></a></dd>
                                                <dt>Package</dt>
                            <dd><div class="namespace-wrapper">Default</div></dd>
                                                <dt>Class hierarchy</dt>
                            <dd class="hierarchy">
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
                                        <div class="namespace-wrapper"><a href="../classes/Swoole.Server.html">\Swoole\Server</a></div>
                                                                    
                                        <div class="namespace-wrapper"><a href="../classes/swoole_server.html">\swoole_server</a></div>
                                                                    
                                        <div class="namespace-wrapper"><a href="../classes/Swoole.Http.Server.html">\Swoole\Http\Server</a></div>
                                                                                                    <div class="namespace-wrapper">\Swoole\WebSocket\Server</div>
                            </dd>

                        
                        
                        
                        
                                                                        </dl>
                    <h2>Tags</h2>
                    <table class="table table-condensed">
                                            <tr><td colspan="2"><em>None found</em></td></tr>
                                        </table>
                </aside>
            </div>

                        
                                    <a id="properties" name="properties"></a>
            <div class="row-fluid">
                <div class="span8 content class">
                    <h2>Properties</h2>
                </div>
                <aside class="span4 detailsbar"></aside>
            </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_master_pid" name="property_master_pid" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$master_pid</h3>
                <pre class="signature">$master_pid : integer</pre>
                <p><em>主进程PID</em></p>
                

                                <h4>Type</h4>
                integer
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_manager_pid" name="property_manager_pid" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$manager_pid</h3>
                <pre class="signature">$manager_pid : integer</pre>
                <p><em>当前服务器管理进程的PID</em></p>
                <p>!! 只能在onStart/onWorkerStart之后获取到</p>

                                <h4>Type</h4>
                integer
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_worker_id" name="property_worker_id" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$worker_id</h3>
                <pre class="signature">$worker_id : integer</pre>
                <p><em>当前Worker进程的编号</em></p>
                <p>这个属性与onWorkerStart时的$worker_id是相同的。</p>
<ul>
<li>Worker进程ID范围是[0, $serv-&gt;setting['worker_num'])</li>
<li>task进程ID范围是[$serv-&gt;setting['worker_num'], $serv-&gt;setting['worker_num'] + $serv-&gt;setting['task_worker_num'])</li>
</ul>
<p>工作进程重启后worker_id的值是不变的</p>

                                <h4>Type</h4>
                integer
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_worker_pid" name="property_worker_pid" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$worker_pid</h3>
                <pre class="signature">$worker_pid : integer</pre>
                <p><em>当前Worker进程的ID，0 - ($serv-&gt;setting[worker_num]-1)</em></p>
                

                                <h4>Type</h4>
                integer
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_taskworker" name="property_taskworker" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$taskworker</h3>
                <pre class="signature">$taskworker : boolean</pre>
                <p><em>是否 Task 工作进程</em></p>
                <p>true  表示当前的进程是Task工作进程
false 表示当前的进程是Worker进程</p>

                                <h4>Type</h4>
                boolean
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="property_connections" name="property_connections" class="anchor"></a>
            <article class="property">
                <h3 class="public ">$connections</h3>
                <pre class="signature">$connections : array</pre>
                <p><em>TCP连接迭代器，可以使用foreach遍历服务器当前所有的连接，此属性的功能与swoole_server-&gt;connnection_list是一致的，但是更加友好。遍历的元素为单个连接的fd</em></p>
                <p>连接迭代器依赖pcre库，未安装pcre库无法使用此功能</p>
<pre><code> foreach($server-&gt;connections as $fd)
 {
     $server-&gt;send($fd, "hello");
 }

 echo "当前服务器共有 ".count($server-&gt;connections). " 个连接\n";</code></pre>

                                <h4>Type</h4>
                array
                                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                        <dl>
                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                                            
                                    <a id="methods" name="methods"></a>
            <div class="row-fluid">
                <div class="span8 content class"><h2>Methods</h2></div>
                <aside class="span4 detailsbar"></aside>
            </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_setGlobal" name="method_setGlobal" class="anchor"></a>
            <article class="method">
                <h3 class="public ">setGlobal()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">setGlobal(  <span class="argument">$flag</span>, integer  <span class="argument">$request_flag</span>) </pre>
                <p><em>启用数据合并，HTTP请求数据到PHP的GET/POST/COOKIE全局数组</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$flag </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$request_flag </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Http.Server.html"><div class="path-wrapper">\Swoole\Http\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method___construct" name="method___construct" class="anchor"></a>
            <article class="method">
                <h3 class="public ">__construct()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">__construct(  <span class="argument">$host</span>,   <span class="argument">$port</span>, integer  <span class="argument">$mode = SWOOLE_PROCESS</span>, integer  <span class="argument">$sock_type = SWOOLE_SOCK_TCP</span>) </pre>
                <p><em>swoole_server构造函数</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$host </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td></td>
                                <td>$port </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$mode </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$sock_type </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_on" name="method_on" class="anchor"></a>
            <article class="method">
                <h3 class="public ">on()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">on(string  <span class="argument">$event</span>, mixed  <span class="argument">$callback</span>) </pre>
                <p><em>注册事件回调函数，与swoole_server-&gt;on相同。swoole_http_server-&gt;on的不同之处是：</em></p>
                <ul>
<li>swoole_http_server-&gt;on不接受onConnect/onReceive回调设置</li>
<li>
<p>swoole_http_server-&gt;on 额外接受1种新的事件类型onRequest</p>
<p>事件列表</p>
<ul>
<li>onStart</li>
<li>onShutdown</li>
<li>onWorkerStart</li>
<li>onWorkerStop</li>
<li>onTimer</li>
<li>onConnect</li>
<li>onReceive</li>
<li>onClose</li>
<li>onTask</li>
<li>onFinish</li>
<li>onPipeMessage</li>
<li>onWorkerError</li>
<li>onManagerStart</li>
<li>onManagerStop</li>
</ul>
<p>$http_server-&gt;on('request', function(swoole_http_request $request, swoole_http_response $response) {
$response-&gt;end(&quot;<h1>hello swoole</h1>&quot;);
})</p>
</li>
</ul>
<p>在收到一个完整的Http请求后，会回调此函数。回调函数共有2个参数：</p>
<ul>
<li>$request，Http请求信息对象，包含了header/get/post/cookie等相关信息</li>
<li>$response，Http响应对象，支持cookie/header/status等Http操作</li>
</ul>
<p>!! $response/$request 对象传递给其他函数时，不要加&amp;引用符号</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$event </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$callback </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_set" name="method_set" class="anchor"></a>
            <article class="method">
                <h3 class="public ">set()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">set(array  <span class="argument">$setting</span>) </pre>
                <p><em>设置运行时参数</em></p>
                <p>swoole_server-&gt;set函数用于设置swoole_server运行时的各项参数。服务器启动后通过$serv-&gt;setting来访问set函数设置的参数数组。</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>array</td>
                                <td>$setting </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_start" name="method_start" class="anchor"></a>
            <article class="method">
                <h3 class="public ">start()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">start() : boolean</pre>
                <p><em>启动server，监听所有TCP/UDP端口</em></p>
                <p>启动成功后会创建worker_num+2个进程。主进程+Manager进程+worker_num个Worker进程</p>

                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_send" name="method_send" class="anchor"></a>
            <article class="method">
                <h3 class="public ">send()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">send(integer  <span class="argument">$fd</span>, string  <span class="argument">$data</span>, integer  <span class="argument">$from_id</span>) : boolean</pre>
                <p><em>向客户端发送数据</em></p>
                <ul>
<li>$data，发送的数据。TCP协议最大不得超过2M，UDP协议不得超过64K
<ul>
<li>发送成功会返回true，如果连接已被关闭或发送失败会返回false</li>
</ul></li>
</ul>
<p>TCP服务器</p>
<ul>
<li>send操作具有原子性，多个进程同时调用send向同一个连接发送数据，不会发生数据混杂</li>
<li>如果要发送超过2M的数据，可以将数据写入临时文件，然后通过sendfile接口进行发送</li>
</ul>
<p>swoole-1.6以上版本不需要$from_id</p>
<p>UDP服务器</p>
<ul>
<li>send操作会直接在worker进程内发送数据包，不会再经过主进程转发</li>
<li>使用fd保存客户端IP，from_id保存from_fd和port</li>
<li>如果在onReceive后立即向客户端发送数据，可以不传$from_id</li>
<li>如果向其他UDP客户端发送数据，必须要传入from_id</li>
<li>在外网服务中发送超过64K的数据会分成多个传输单元进行发送，如果其中一个单元丢包，会导致整个包被丢弃。所以外网服务，建议发送1.5K以下的数据包</li>
</ul>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>string</td>
                                <td>$data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$from_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_sendto" name="method_sendto" class="anchor"></a>
            <article class="method">
                <h3 class="public ">sendto()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">sendto(string  <span class="argument">$ip</span>, integer  <span class="argument">$port</span>, string  <span class="argument">$data</span>, boolean  <span class="argument">$ipv6 = false</span>) : boolean</pre>
                <p><em>向任意的客户端IP:PORT发送UDP数据包</em></p>
                <ul>
<li>$ip为IPv4字符串，如192.168.1.102。如果IP不合法会返回错误
<ul>
<li>$port为 1-65535的网络端口号，如果端口错误发送会失败</li>
<li>$data要发送的数据内容，可以是文本或者二进制内容</li>
<li>$ipv6 是否为IPv6地址，可选参数，默认为false</li>
</ul></li>
</ul>
<p>示例</p>
<pre><code> //向IP地址为220.181.57.216主机的9502端口发送一个hello world字符串。
 $server-&gt;sendto('220.181.57.216', 9502, "hello world");
 //向IPv6服务器发送UDP数据包
 $server-&gt;sendto('2600:3c00::f03c:91ff:fe73:e98f', 9501, "hello world", true);</code></pre>
<p>server必须监听了UDP的端口，才可以使用swoole_server-&gt;sendto
server必须监听了UDP6的端口，才可以使用swoole_server-&gt;sendto向IPv6地址发送数据</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$ip </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$port </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>string</td>
                                <td>$data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>boolean</td>
                                <td>$ipv6 </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_close" name="method_close" class="anchor"></a>
            <article class="method">
                <h3 class="public ">close()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">close(integer  <span class="argument">$fd</span>, integer  <span class="argument">$from_id</span>) : boolean</pre>
                <p><em>关闭客户端连接</em></p>
                <p>!! swoole-1.6以上版本不需要$from_id swoole-1.5.8以下的版本，务必要传入正确的$from_id，否则可能会导致连接泄露</p>
<p>操作成功返回true，失败返回false.</p>
<p>Server主动close连接，也一样会触发onClose事件。不要在close之后写清理逻辑。应当放置到onClose回调中处理。</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$from_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_taskwait" name="method_taskwait" class="anchor"></a>
            <article class="method">
                <h3 class="public ">taskwait()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">taskwait(mixed  <span class="argument">$task_data</span>, float  <span class="argument">$timeout = 0.5</span>, integer  <span class="argument">$dst_worker_id = -1</span>) : string</pre>
                <p><em>taskwait与task方法作用相同，用于投递一个异步的任务到task进程池去执行。
与task不同的是taskwait是阻塞等待的，直到任务完成或者超时返回</em></p>
                <p>$result为任务执行的结果，由$serv-&gt;finish函数发出。如果此任务超时，这里会返回false。</p>
<p>taskwait是阻塞接口，如果你的Server是全异步的请使用swoole_server::task和swoole_server::finish,不要使用taskwait
第3个参数可以制定要给投递给哪个task进程，传入ID即可，范围是0 - serv-&gt;task_worker_num
$dst_worker_id在1.6.11+后可用，默认为随机投递
taskwait方法不能在task进程中调用</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>mixed</td>
                                <td>$task_data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>float</td>
                                <td>$timeout </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$dst_worker_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    string
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_task" name="method_task" class="anchor"></a>
            <article class="method">
                <h3 class="public ">task()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">task(mixed  <span class="argument">$data</span>, integer  <span class="argument">$dst_worker_id = -1</span>) : boolean</pre>
                <p><em>投递一个异步任务到task_worker池中。此函数会立即返回。worker进程可以继续处理新的请求</em></p>
                <ul>
<li>$data要投递的任务数据，可以为除资源类型之外的任意PHP变量
<ul>
<li>$dst_worker_id可以制定要给投递给哪个task进程，传入ID即可，范围是0 - serv-&gt;task_worker_num</li>
<li>返回值为整数($task_id)，表示此任务的ID。如果有finish回应，onFinish回调中会携带$task_id参数</li>
</ul></li>
</ul>
<p>此功能用于将慢速的任务异步地去执行，比如一个聊天室服务器，可以用它来进行发送广播。当任务完成时，在task进程中调用$serv-&gt;finish(&quot;finish&quot;)告诉worker进程此任务已完成。当然swoole_server-&gt;finish是可选的。</p>
<ul>
<li>AsyncTask功能在1.6.4版本增加，默认不启动task功能，需要在手工设置task_worker_num来启动此功能</li>
<li>task_worker的数量在swoole_server::set参数中调整，如task_worker_num =&gt; 64，表示启动64个进程来接收异步任务</li>
</ul>
<p>注意事项</p>
<ul>
<li>使用swoole_server_task必须为Server设置onTask和onFinish回调，否则swoole_server-&gt;start会失败</li>
<li>task操作的次数必须小于onTask处理速度，如果投递容量超过处理能力，task会塞满缓存区，导致worker进程发生阻塞。worker进程将无法接收新的请求</li>
</ul>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>mixed</td>
                                <td>$data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$dst_worker_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_sendMessage" name="method_sendMessage" class="anchor"></a>
            <article class="method">
                <h3 class="public ">sendMessage()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">sendMessage(string  <span class="argument">$message</span>, integer  <span class="argument">$dst_worker_id = -1</span>) : boolean</pre>
                <p><em>此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件</em></p>
                <ul>
<li>$message为发送的消息数据内容
<ul>
<li>$dst_worker_id为目标进程的ID，范围是0 ~ (worker_num + task_worker_num - 1)</li>
</ul></li>
</ul>
<p>!! 使用sendMessage必须注册onPipeMessage事件回调函数</p>
<pre><code> $serv = new swoole_server("0.0.0.0", 9501);
 $serv-&gt;set(array(
     'worker_num' =&gt; 2,
     'task_worker_num' =&gt; 2,
 ));
 $serv-&gt;on('pipeMessage', function($serv, $src_worker_id, $data) {
     echo "#{$serv-&gt;worker_id} message from #$src_worker_id: $data\n";
 });
 $serv-&gt;on('task', function ($serv, $task_id, $from_id, $data){
     var_dump($task_id, $from_id, $data);
 });
 $serv-&gt;on('finish', function ($serv, $fd, $from_id){

 });
 $serv-&gt;on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
     if (trim($data) == 'task')
     {
         $serv-&gt;task("async task coming");
     }
     else
     {
         $worker_id = 1 - $serv-&gt;worker_id;
         $serv-&gt;sendMessage("hello task process", $worker_id);
     }
 });

 $serv-&gt;start();</code></pre>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$message </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$dst_worker_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_finish" name="method_finish" class="anchor"></a>
            <article class="method">
                <h3 class="public ">finish()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">finish(string  <span class="argument">$task_data</span>) </pre>
                <p><em>此函数用于在task进程中通知worker进程，投递的任务已完成。此函数可以传递结果数据给worker进程</em></p>
                <p>$serv-&gt;finish(&quot;response&quot;);</p>
<p>使用swoole_server::finish函数必须为Server设置onFinish回调函数。此函数只可用于task进程的onTask回调中</p>
<p>swoole_server::finish是可选的。如果worker进程不关心任务执行的结果，不需要调用此函数
在onTask回调函数中return字符串，等同于调用finish</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$task_data </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_heartbeat" name="method_heartbeat" class="anchor"></a>
            <article class="method">
                <h3 class="public ">heartbeat()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">heartbeat(boolean  <span class="argument">$if_close_connection = true</span>) : array</pre>
                <p><em>检测服务器所有连接，并找出已经超过约定时间的连接。
如果指定if_close_connection，则自动关闭超时的连接。未指定仅返回连接的fd数组&#039;</em></p>
                <ul>
<li>$if_close_connection是否关闭超时的连接，默认为true
<ul>
<li>调用成功将返回一个连续数组，元素是已关闭的$fd。</li>
<li>调用失败返回false</li>
</ul></li>
</ul>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>boolean</td>
                                <td>$if_close_connection </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    array
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_connection_info" name="method_connection_info" class="anchor"></a>
            <article class="method">
                <h3 class="public ">connection_info()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">connection_info(integer  <span class="argument">$fd</span>, integer  <span class="argument">$from_id = -1</span>) : array</pre>
                <p><em>获取连接的信息</em></p>
                <p>connection_info可用于UDP服务器，但需要传入from_id参数</p>
<pre><code> array (
      'from_id' =&gt; 0,
      'from_fd' =&gt; 12,
      'connect_time' =&gt; 1392895129,
      'last_time' =&gt; 1392895137,
      'from_port' =&gt; 9501,
      'remote_port' =&gt; 48918,
      'remote_ip' =&gt; '127.0.0.1',
 )</code></pre>
<ul>
<li>$udp_client = $serv-&gt;connection_info($fd, $from_id);</li>
<li>var_dump($udp_client);</li>
<li>from_id 来自哪个reactor线程</li>
<li>server_fd 来自哪个server socket 这里不是客户端连接的fd</li>
<li>server_port 来自哪个Server端口</li>
<li>remote_port 客户端连接的端口</li>
<li>remote_ip 客户端连接的ip</li>
<li>connect_time 连接到Server的时间，单位秒</li>
<li>last_time 最后一次发送数据的时间，单位秒</li>
</ul>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$from_id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    array
                                            &mdash; <p>| bool</p>
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_connection_list" name="method_connection_list" class="anchor"></a>
            <article class="method">
                <h3 class="public ">connection_list()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">connection_list(integer  <span class="argument">$start_fd = -1</span>, integer  <span class="argument">$pagesize = 100</span>) : array</pre>
                <p><em>用来遍历当前Server所有的客户端连接，connection_list方法是基于共享内存的，不存在IOWait，遍历的速度很快。另外connection_list会返回所有TCP连接，而不仅仅是当前worker进程的TCP连接</em></p>
                <p>示例：</p>
<pre><code> $start_fd = 0;
 while(true)
 {
     $conn_list = $serv-&gt;connection_list($start_fd, 10);
     if($conn_list===false or count($conn_list) === 0)
     {
         echo "finish\n";
         break;
     }
     $start_fd = end($conn_list);
     var_dump($conn_list);
     foreach($conn_list as $fd)
     {
         $serv-&gt;send($fd, "broadcast");
     }
 }</code></pre>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$start_fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$pagesize </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    array
                                            &mdash; <p>| bool</p>
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_reload" name="method_reload" class="anchor"></a>
            <article class="method">
                <h3 class="public ">reload()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">reload() : boolean</pre>
                <p><em>重启所有worker进程</em></p>
                <p>一台繁忙的后端服务器随时都在处理请求，如果管理员通过kill进程方式来终止/重启服务器程序，可能导致刚好代码执行到一半终止。 这种情况下会产生数据的不一致。如交易系统中，支付逻辑的下一段是发货，假设在支付逻辑之后进程被终止了。会导致用户支付了货币，但并没有发货，后果非常严重。</p>
<p>Swoole提供了柔性终止/重启的机制，管理员只需要向SwooleServer发送特定的信号，Server的worker进程可以安全的结束。</p>
<ul>
<li>SIGTERM: 向主进程发送此信号服务器将安全终止</li>
<li>在PHP代码中可以调用$serv-&gt;shutdown()完成此操作</li>
<li>SIGUSR1: 向管理进程发送SIGUSR1信号，将平稳地restart所有worker进程</li>
<li>在PHP代码中可以调用$serv-&gt;reload()完成此操作</li>
<li>
<p>swoole的reload有保护机制，当一次reload正在进行时，收到新的重启信号会丢弃</p>
<h1>重启所有worker进程</h1>
<p>kill -USR1 主进程PID</p>
</li>
</ul>
<p>仅重启task_worker的功能。只需向服务器发送SIGUSR2即可。</p>
<h1>仅重启task进程</h1>
<p>kill -USR2 主进程PID
平滑重启只对onWorkerStart或onReceive等在Worker进程中include/require的PHP文件有效，Server启动前就已经include/require的PHP文件，不能通过平滑重启重新加载
对于Server的配置即$serv-&gt;set()中传入的参数设置，必须关闭/重启整个Server才可以重新加载
Server可以监听一个内网端口，然后可以接收远程的控制命令，去重启所有worker</p>

                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_shutdown" name="method_shutdown" class="anchor"></a>
            <article class="method">
                <h3 class="public ">shutdown()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">shutdown() : boolean</pre>
                <p><em>关闭服务器</em></p>
                <p>此函数可以用在worker进程内。向主进程发送SIGTERM也可以实现关闭服务器。</p>
<p>kill -15 主进程PID</p>

                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_addlistener" name="method_addlistener" class="anchor"></a>
            <article class="method">
                <h3 class="public ">addlistener()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">addlistener(string  <span class="argument">$host</span>, integer  <span class="argument">$port</span>, integer  <span class="argument">$type = SWOOLE_SOCK_TCP</span>) : \swoole_server_port|boolean</pre>
                <p><em>Swoole提供了swoole_server::addListener来增加监听的端口。业务代码中可以通过调用swoole_server::connection_info来获取某个连接来自于哪个端口</em></p>
                <ul>
<li>SWOOLE_TCP/SWOOLE_SOCK_TCP tcp ipv4 socket</li>
<li>SWOOLE_TCP6/SWOOLE_SOCK_TCP6 tcp ipv6 socket</li>
<li>SWOOLE_UDP/SWOOLE_SOCK_UDP udp ipv4 socket</li>
<li>SWOOLE_UDP6/SWOOLE_SOCK_UDP6 udp ipv6 socket</li>
<li>SWOOLE_UNIX_DGRAM unix socket dgram</li>
<li>SWOOLE_UNIX_STREAM unix socket stream</li>
</ul>
<p>可以混合使用UDP/TCP，同时监听内网和外网端口。 示例：</p>
<pre><code> $serv-&gt;addlistener("127.0.0.1", 9502, SWOOLE_SOCK_TCP);
 $serv-&gt;addlistener("192.168.1.100", 9503, SWOOLE_SOCK_TCP);
 $serv-&gt;addlistener("0.0.0.0", 9504, SWOOLE_SOCK_UDP);
 $serv-&gt;addlistener("/var/run/myserv.sock", 0, SWOOLE_UNIX_STREAM);</code></pre>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$host </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$port </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$type </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    <a href="../classes/swoole_server_port.html">\swoole_server_port</a>|boolean
                                            &mdash; <p>如果成功，1.8.0以上版本返回swoole_server_port，以下返回TRUE；如果失败返回FALSE</p>
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_stats" name="method_stats" class="anchor"></a>
            <article class="method">
                <h3 class="public ">stats()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">stats() : array</pre>
                <p><em>得到当前Server的活动TCP连接数，启动时间，accpet/close的总次数等信息</em></p>
                <p>array (
'start_time' =&gt; 1409831644,
'connection_num' =&gt; 1,
'accept_count' =&gt; 1,
'close_count' =&gt; 0,
);</p>
<ul>
<li>start_time 服务器启动的时间</li>
<li>connection_num 当前连接的数量</li>
<li>accept_count 接受了多少个连接</li>
<li>close_count 关闭的连接数量</li>
<li>tasking_num 当前正在排队的任务数</li>
</ul>

                
                
                                    <h4>Returns</h4>
                    array
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_after" name="method_after" class="anchor"></a>
            <article class="method">
                <h3 class="public ">after()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">after(integer  <span class="argument">$after_time_ms</span>, mixed  <span class="argument">$callback_function</span>, mixed  <span class="argument">$param = null</span>) </pre>
                <p><em>在指定的时间后执行函数</em></p>
                <p>swoole_server::after函数是一个一次性定时器，执行完成后就会销毁。</p>
<p>$after_time_ms 指定时间，单位为毫秒
$callback_function 时间到期后所执行的函数，必须是可以调用的。callback函数不接受任何参数
$after_time_ms 最大不得超过 86400000
此方法是swoole_timer_after函数的别名</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$after_time_ms </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$callback_function </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$param </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_listen" name="method_listen" class="anchor"></a>
            <article class="method">
                <h3 class="public ">listen()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">listen(  <span class="argument">$host</span>,   <span class="argument">$port</span>,   <span class="argument">$type = SWOOLE_SOCK_TCP</span>) </pre>
                <p><em></em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$host </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td></td>
                                <td>$port </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td></td>
                                <td>$type </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_addProcess" name="method_addProcess" class="anchor"></a>
            <article class="method">
                <h3 class="public ">addProcess()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">addProcess(\Swoole\swoole_process  <span class="argument">$process</span>) </pre>
                <p><em>添加一个用户自定义的工作进程</em></p>
                <ul>
<li>$process 为swoole_process对象，注意不需要执行start。在swoole_server启动时会自动创建进程，并执行指定的子进程函数
<ul>
<li>创建的子进程可以调用$server对象提供的各个方法，如connection_list/connection_info/stats</li>
<li>在worker进程中可以调用$process提供的方法与子进程进行通信</li>
<li>此函数通常用于创建一个特殊的工作进程，用于监控、上报或者其他特殊的任务。</li>
</ul></li>
</ul>
<p>子进程会托管到Manager进程，如果发生致命错误，manager进程会重新创建一个</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>\Swoole\swoole_process</td>
                                <td>$process </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_addtimer" name="method_addtimer" class="anchor"></a>
            <article class="method">
                <h3 class="public ">addtimer()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">addtimer(integer  <span class="argument">$interval</span>) : boolean</pre>
                <p><em>设置定时器。1.6.12版本前此函数不能用在消息队列模式下，1.6.12后消息队列IPC模式也可以使用定时器</em></p>
                <p>第二个参数是定时器的间隔时间，单位为毫秒。swoole定时器的最小颗粒是1毫秒。支持多个定时器。此函数可以用于worker进程中。</p>
<ul>
<li>swoole1.6.5之前支持的单位是秒，所以1.6.5之前传入的参数为1，那在1.6.5后需要传入1000</li>
<li>swoole1.6.5之后，addtimer必须在onStart/onWorkerStart/onConnect/onReceive/onClose等回调函数中才可以使用，否则会抛出错误。并且定时器无效</li>
<li>注意不能存在2个相同间隔时间的定时器</li>
<li>
<p>即使在代码中多次添加一个定时器，也只会有1个生效</p>
<p>增加定时器后需要为Server设置onTimer回调函数，否则Server将无法启动。多个定时器都会回调此函数。在这个函数内需要自行switch，根据interval的值来判断是来自于哪个定时器。</p>
<p>// 面向对象风格
$serv-&gt;addtimer(1000); //1s
$serv-&gt;addtimer(20); //20ms</p>
</li>
</ul>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$interval </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_deltimer" name="method_deltimer" class="anchor"></a>
            <article class="method">
                <h3 class="public ">deltimer()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">deltimer(  <span class="argument">$interval</span>) </pre>
                <p><em>删除定时器</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$interval </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_tick" name="method_tick" class="anchor"></a>
            <article class="method">
                <h3 class="public ">tick()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">tick(  <span class="argument">$interval_ms</span>, mixed  <span class="argument">$callback</span>, mixed  <span class="argument">$param = null</span>) : integer</pre>
                <p><em>增加tick定时器</em></p>
                <p>可以自定义回调函数。此函数是swoole_timer_tick的别名</p>
<p>worker进程结束运行后，所有定时器都会自动销毁</p>
<p>设置一个间隔时钟定时器，与after定时器不同的是tick定时器会持续触发，直到调用swoole_timer_clear清除。与swoole_timer_add不同的是tick定时器可以存在多个相同间隔时间的定时器。</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$interval_ms </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$callback </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$param </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    integer
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_clearAfter" name="method_clearAfter" class="anchor"></a>
            <article class="method">
                <h3 class="public ">clearAfter()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">clearAfter(  <span class="argument">$id</span>) </pre>
                <p><em>删除设定的定时器，此定时器不会再触发</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$id </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_handler" name="method_handler" class="anchor"></a>
            <article class="method">
                <h3 class="public ">handler()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">handler(string  <span class="argument">$event_name</span>, mixed  <span class="argument">$event_callback_function</span>) : boolean</pre>
                <p><em>设置Server的事件回调函数</em></p>
                <p>第一个参数是swoole的资源对象
第二个参数是回调的名称, 大小写不敏感，具体内容参考回调函数列表
第三个函数是回调的PHP函数，可以是字符串，数组，匿名函数。比如
handler/on/set 方法只能在swoole_server::start前调用</p>
<pre><code> $serv-&gt;handler('onStart', 'my_onStart');
 $serv-&gt;handler('onStart', array($this, 'my_onStart'));
 $serv-&gt;handler('onStart', 'myClass::onStart');</code></pre>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>string</td>
                                <td>$event_name </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>mixed</td>
                                <td>$event_callback_function </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_sendfile" name="method_sendfile" class="anchor"></a>
            <article class="method">
                <h3 class="public ">sendfile()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">sendfile(integer  <span class="argument">$fd</span>, string  <span class="argument">$filename</span>) : boolean</pre>
                <p><em>发送文件到TCP客户端连接</em></p>
                <p>endfile函数调用OS提供的sendfile系统调用，由操作系统直接读取文件并写入socket。sendfile只有2次内存拷贝，使用此函数可以降低发送大量文件时操作系统的CPU和内存占用。</p>
<p>$filename 要发送的文件路径，如果文件不存在会返回false
操作成功返回true，失败返回false
此函数与swoole_server-&gt;send都是向客户端发送数据，不同的是sendfile的数据来自于指定的文件。</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>string</td>
                                <td>$filename </td>
                                <td><p>文件绝对路径</p></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_bind" name="method_bind" class="anchor"></a>
            <article class="method">
                <h3 class="public ">bind()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">bind(integer  <span class="argument">$fd</span>, integer  <span class="argument">$uid</span>) : boolean</pre>
                <p><em>将连接绑定一个用户定义的ID，可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程</em></p>
                <p>在默认的dispatch_mode=2设置下，server会按照socket fd来分配连接数据到不同的worker。
因为fd是不稳定的，一个客户端断开后重新连接，fd会发生改变。这样这个客户端的数据就会被分配到别的Worker。
使用bind之后就可以按照用户定义的ID进行分配。即使断线重连，相同uid的TCP连接数据会被分配相同的Worker进程。</p>
<ul>
<li>$fd 连接的文件描述符</li>
<li>$uid 指定UID</li>
</ul>
<p>同一个连接只能被bind一次，如果已经绑定了uid，再次调用bind会返回false
可以使用$serv-&gt;connection_info($fd) 查看连接所绑定uid的值</p>

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>integer</td>
                                <td>$uid </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_getSocket" name="method_getSocket" class="anchor"></a>
            <article class="method">
                <h3 class="public ">getSocket()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">getSocket(  <span class="argument">$port</span>) : resource</pre>
                <p><em>根据监听的端口号获取ServerSocket，返回一个sockets资源</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$port </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    resource
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_exist" name="method_exist" class="anchor"></a>
            <article class="method">
                <h3 class="public ">exist()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">exist(integer  <span class="argument">$fd</span>) : boolean</pre>
                <p><em>判断fd对应的连接是否存在</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_defer" name="method_defer" class="anchor"></a>
            <article class="method">
                <h3 class="public ">defer()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">defer(callable  <span class="argument">$callback</span>) </pre>
                <p><em></em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>callable</td>
                                <td>$callback </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_getClientInfo" name="method_getClientInfo" class="anchor"></a>
            <article class="method">
                <h3 class="public ">getClientInfo()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">getClientInfo(integer  <span class="argument">$fd</span>) : boolean</pre>
                <p><em></em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td>integer</td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    boolean
                                            &mdash; <p>| array</p>
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                    <dt>Inherited from</dt>
                    <dd><a href="../classes/Swoole.Server.html"><div class="path-wrapper">\Swoole\Server</div></a></dd>
                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_push" name="method_push" class="anchor"></a>
            <article class="method">
                <h3 class="public ">push()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">push(  <span class="argument">$fd</span>,   <span class="argument">$data</span>, boolean  <span class="argument">$binary_data = false</span>, boolean  <span class="argument">$finish = true</span>) </pre>
                <p><em>向某个WebSocket客户端连接推送数据</em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$fd </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td></td>
                                <td>$data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>boolean</td>
                                <td>$binary_data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>boolean</td>
                                <td>$finish </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                                                            <dl>
                                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                    <div class="row-fluid">
        <div class="span8 content class">
            <a id="method_pack" name="method_pack" class="anchor"></a>
            <article class="method">
                <h3 class="public ">pack()</h3>
                <a href="#source-view" role="button" class="pull-right btn" data-toggle="modal" style="font-size: 1.1em; padding: 9px 14px"><i class="icon-code"></i></a>
                <pre class="signature" style="margin-right: 54px;">pack(  <span class="argument">$data</span>,   <span class="argument">$opcode = WEBSOCKET_OPCODE_TEXT</span>, boolean  <span class="argument">$finish = true</span>, boolean  <span class="argument">$mask = false</span>) : string</pre>
                <p><em></em></p>
                

                                    <h4>Parameters</h4>
                    <table class="table table-condensed table-hover">
                                                    <tr>
                                <td></td>
                                <td>$data </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td></td>
                                <td>$opcode </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>boolean</td>
                                <td>$finish </td>
                                <td></td>
                            </tr>
                                                    <tr>
                                <td>boolean</td>
                                <td>$mask </td>
                                <td></td>
                            </tr>
                                            </table>
                
                
                                    <h4>Returns</h4>
                    string
                                    				
                            </article>
        </div>
        <aside class="span4 detailsbar">
            <h1><i class="icon-arrow-down"></i></h1>
                            <span class="label label-info">static</span>
                                                            <dl>
                                                                            </dl>
            <h2>Tags</h2>
            <table class="table table-condensed">
                                    <tr><td colspan="2"><em>None found</em></td></tr>
                            </table>
        </aside>
    </div>

                                                                    </div>
    </section>

    <div id="source-view" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="source-view-label" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="source-view-label">Server.php</h3>
        </div>
        <div class="modal-body">
            <pre data-src="../files/Websocket/Server.php.txt" class="language-php line-numbers"></pre>
        </div>
    </div>

    <footer class="row-fluid">
        <section class="span10 offset2">
            <section class="row-fluid">
                <section class="span10 offset1">
                    <section class="row-fluid footer-sections">
                        <section class="span4">
                                                        <h1><i class="icon-code"></i></h1>
                            <div>
                                <ul>
                                                                            <li><a href="../namespaces/Swoole.html">\Swoole</a></li>
                                                                    </ul>
                            </div>
                        </section>
                        <section class="span4">
                                                        <h1><i class="icon-bar-chart"></i></h1>
                            <div>
                                <ul>
                                    <li><a href="../graphs/class.html">Class Hierarchy Diagram</a></li>
                                </ul>
                            </div>
                        </section>
                        <section class="span4">
                                                        <h1><i class="icon-pushpin"></i></h1>
                            <div>
                                <ul>
                                    <li><a href="../reports/errors.html">Errors</a></li>
                                    <li><a href="../reports/markers.html">Markers</a></li>
                                </ul>
                            </div>
                        </section>
                    </section>
                </section>
            </section>
            <section class="row-fluid">
                <section class="span10 offset1">
                    <hr />
                    Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor </a> and authored
                    on February 25th, 2016 at 20:01.
                </section>
            </section>
        </section>
    </footer>
</div>

</body>
</html>
